// Role management related APIs
import request from '@/utils/request'

// Get role list (pagination)
export function getRoleList(params) {
  // 转换参数名称以匹配后端RoleDTO
  const transformedParams = {
    page: params.page,
    pageSize: params.pageSize,
    name: params.name,
    label: params.roleKey
  }
  return request({
    url: '/api/roles',
    method: 'get',
    params: transformedParams
  })
}

// Add role
export function addRole(data) {
  // 转换参数名称以匹配后端
  const transformedData = {
    name: data.name,
    label: data.roleKey,
    remark: data.remark
  }
  return request({
    url: '/api/roles',
    method: 'post',
    data: transformedData
  })
}

// Get role by ID
export function getRoleById(id) {
  return request({
    url: `/api/roles/${id}`,
    method: 'get'
  })
}

// Update role
export function updateRole(data) {
  // 转换参数名称以匹配后端
  const transformedData = {
    id: data.id,
    name: data.name,
    label: data.roleKey,
    remark: data.remark
  }
  return request({
    url: '/api/roles',
    method: 'put',
    data: transformedData
  })
}

// Delete role
export function deleteRole(id) {
  return request({
    url: `/api/roles/${id}`,
    method: 'delete'
  })
}

// Get all roles list
export function getAllRoles() {
  return request({
    url: '/api/roles/list',
    method: 'get'
  })
}